<template>
    <div>
        <headerComponent></headerComponent>
        <div style="padding-bottom: 60px">
            <div v-if="certified" class="personContent">
                <div v-if="profile.length != 0" class="center">
                    <el-row :gutter="10">
                        <el-col :span="6" class="userinfo">
                            <el-card>
                                <div style="display: flex;justify-content: space-between;align-items: center">
                                    <div>
                                        <p style="font-weight: 600;" v-if="person.user">
                                            学员ID：{{person.user.username}}</p>
                                        <p style="font-weight: 600;" v-if="person.name">姓名：{{person.name}}</p>
                                    </div>
                                    <i @click="userInfoIsShow = !userInfoIsShow" style="cursor: pointer"
                                       class="el-icon-d-caret"></i>
                                </div>
                                <div v-show="userInfoIsShow">
                                    <p v-if="person.last_py">
                                        姓拼音：{{ person.last_py }}
                                    </p>
                                    <p v-if="person.first_py">
                                        名拼音：{{ person.first_py }}
                                    </p>
                                    <p v-if="person.gender_display">
                                        性别：{{ person.gender_display }}
                                    </p>
                                    <p v-if="person.user">
                                        手机号码：{{ person.user.phone }}
                                    </p>
                                    <p v-if="person.email">
                                        电子邮箱：{{ person.email }}
                                    </p>
                                    <p v-if="person.user">
                                        证件类型：{{ cardOptions[person.user.user_type] }}
                                    </p>
                                    <p v-if="person.card_id">
                                        身份证号：{{ person.card_id | hideMiddle }}
                                    </p>
                                    <p v-if="person.birthday">
                                        出生日期：{{ person.birthday | formatDate }}
                                    </p>
                                    <!--              学校信息{{person}}-->
                                    <el-divider></el-divider>
                                    <p v-if="person.hig_edu">
                                        最高学历：{{ person.hig_edu }}
                                    </p>
                                    <p v-if="person.major">
                                        相关专业：{{ person.major }}
                                    </p>
                                    <p v-if="person.grad_time">
                                        毕业年份：{{ person.grad_time | formatDateMath }}
                                    </p>
                                </div>
                            </el-card>
                            <el-card style="margin-top: 10px">
                                <div style="display: flex;justify-content: space-between;align-items: center;margin-bottom:10px">
                                    <span style="font-weight: 600">工作信息</span>
                                    <i @click="workInfoIsShow = !workInfoIsShow" style="cursor: pointer"
                                       class="el-icon-d-caret"></i>
                                </div>
                                <div v-show="workInfoIsShow">
                                    <div v-if="person.com_name">
                                        <h5>单位名称：</h5>
                                        <h6 class="h6">{{ person.com_name }}</h6>
                                    </div>
                                    <div v-if="person.ind_type">
                                        <h5>行业类型：</h5>
                                        <h6 class="h6">{{ ind_typeList.filter((element) => element.value ==
                                            person.ind_type)[0].name }}</h6>
                                    </div>
                                    <div v-if="person.com_type">
                                        <h5>单位类型：</h5>
                                        <h6 class="h6">{{ com_typeList.filter((element) => element.value ==
                                            person.com_type)[0].name }}</h6>
                                    </div>
                                    <div v-if="person.work_duty">
                                        <h5>职务：</h5>
                                        <h6 class="h6">{{ person.work_duty.split('#')[0] }}</h6>
                                    </div>
                                    <div v-if="person.work_age">
                                        <h5>从事薪酬管理（含薪税服务）工作年限（含实习经历）：</h5>
                                        <h6 class="h6">{{ person.work_age }}年</h6>
                                    </div>
                                    <div v-if="person.province">
                                        <h5>工作区域：</h5>
                                        <h6 class="h6">{{ person.province + '/' + person.city + '/' + person.region
                                            }}</h6>
                                    </div>
                                    <div v-if="person.cert">
                                        <h5>相关资质或证书：</h5>
                                        <h6 class="h6">{{ person.cert}}</h6>
                                    </div>
                                </div>
                            </el-card>
                        </el-col>
                        <el-col :span="18" style="margin-top: 10px;">
                            <el-row :gutter="10" type="flex">
                                <el-col :span="14">
                                    <el-card style="height: 100%">
                                        <div slot="header" class="clearfix">
                                            <span style="font-weight: 600">公告</span>
                                            <!--                      <el-button style="float: right; padding: 3px 0" type="text">更多+</el-button>-->
                                        </div>
                                        <div
                                                class="notilist"
                                                v-for="item in noticeList"
                                        >
                    <span href="#" style="display: flex;
        justify-content: space-between;
        align-items: center;" @click="showNoti(item.title)"><span class="notilist_span">{{ item.title }}</span> <span>{{ item.add_time.split(' ')[0] }}</span></span>
                                        </div>
                                        <el-empty v-if="noticeList.length == 0" :image-size="40"
                                                  description="暂无数据"></el-empty>
                                    </el-card>
                                </el-col>
                                <el-dialog
                                        :title="notice.title"
                                        :visible.sync="notiListDialogVisible"
                                        width="60%"
                                        center>
                                    <div v-html="notice.text">

                                    </div>
                                    <p style="text-align:right;width:100%;">{{notice.add_time ?
                                        notice.add_time.substr(0,10):''}}</p>
                                    <span slot="footer" class="dialog-footer">
                  <el-button @click="notiListDialogVisible = false" size="small">取 消</el-button>
                  <el-button type="primary" @click="notiListDialogVisible = false" size="small">确 定</el-button>
                </span>
                                </el-dialog>
                                <el-col :span="10">
                                    <el-card class="sign_step">
                                        <el-tabs class="tab" v-model="activeName">
                                            <el-tab-pane label="培训报名流程" name="register">
                                                <div style="display: flex;justify-content: flex-end">
                                                    <el-button type="danger" @click="toRegister"
                                                               style="padding: 4px" size="small">培训报名
                                                    </el-button>
                                                </div>
                                                <div>
                                                    <p>1.报名网址：https://ccw.pta-athe.com/</p>
                                                    <p>2.点击注册，输入证件号码进行实名认证</p>
                                                    <p>3.实名认证成功后输入机构代码提交填写报名信息</p>
                                                    <p>4.提交后进入用户个人中心，等待审核</p>
                                                    <p>5.审核通过开通学习账号</p>
                                                    <p>6.满足学习课时后可以点击报考</p>
                                                    <p>7.填写信息后提交进入签署合同页面</p>
                                                    <p>8.审核通过生成准考证和查看合同</p>
                                                </div>
                                            </el-tab-pane>
                                            <el-tab-pane label="考试报名流程" name="exam">
                                                <div>
                                                    <p>1.总部一审后在您的报考科目的信息中会出现点击报考按钮</p>
                                                    <p>2.点击报考按钮先阅读报考须知并确认报考信息提交</p>
                                                    <p>3.进行扫码签字和刷脸认证完成确认书签署</p>
                                                    <p>4.等待机构二审和总部二审</p>
                                                    <p>5.审核全部通过生成准考证号和完整确认书</p>
                                                </div>
                                            </el-tab-pane>
                                        </el-tabs>
                                    </el-card>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-card v-for="item in profile" :key="item.id" style="margin-top: 20px">
                                    <el-row style="margin-bottom: 10px">
                                        <div style="width: 100%;display: flex;justify-content: flex-end">
                                            <div style="display: flex;justify-content: space-between;width: 100%">
                                                <div style="display:flex;line-height:28px;">
                                                    <div style="font-size:14px;font-weight: 600;margin-right: 20px;">
                                                        {{ item.course.name }}
                                                        <el-tag size="small" v-show="item.exam_count > 0 ">再次报考</el-tag>
                                                    </div>
                                                    <div style="display: flex">
                                                        <el-button
                                                                v-if="item.contract_id"
                                                                size="mini"
                                                                @click="lookTransation(item.contract_id)"
                                                        >
                                                            查看报考确认书{{item.signed ? '已签署':'未签署'}}
                                                        </el-button>
                                                        <!--                                                        <el-button-->
                                                        <!--                                                                :disabled="-->
                                                        <!--                                                              item.state_code < 3 ||-->
                                                        <!--                                                              (item.state_code < 7 && item.exam_date)-->
                                                        <!--                                                                ? false-->
                                                        <!--                                                                : true-->
                                                        <!--                                                            "-->
                                                        <!--                                                                v-if="item.contract_id && item.state_code < 8"-->
                                                        <!--                                                                size="mini"-->
                                                        <!--                                                                @click="to_contract(item)"-->
                                                        <!--                                                        >-->
                                                        <!--                                                            {{-->
                                                        <!--                                                            item.contract_id && item.signed ?-->
                                                        <!--                                                            '重新编辑并签署确认书' : '继续签署报考确认书'-->
                                                        <!--                                                            }}-->
                                                        <!--                                                        </el-button>-->
                                                        <el-button
                                                                :disabled="!(ConditionsDisplay(item).allow_edit_1 || ConditionsDisplay(item).allow_edit_2 || ConditionsDisplay(item).contract_reject)"
                                                                v-if="ConditionsDisplay(item).allow_sign"
                                                                size="mini"
                                                                @click="to_contract(item)"
                                                        >
                                                            {{
                                                            item.contract_id && item.signed ?
                                                            '重新编辑并签署确认书' : '继续签署报考确认书'
                                                            }}
                                                        </el-button>
                                                    </div>
                                                </div>
                                                <div style="display: flex">
                                                    <!--                                                    <div style="margin-right: 10px"-->
                                                    <!--                                                         v-if="!item.exam_date && item.state_code > 3 || (item.exam_record.length > 0 && item.exam_record[item.exam_record.length - 1].is_pass === false)">-->
                                                    <!--                                                        <el-button size="small" @click="toExam(item.id)">-->
                                                    <!--                                                            {{-->
                                                    <!--                                                            item.exam_record.length > 0 &&-->
                                                    <!--                                                            item.exam_record[item.exam_record.length - 1].is_pass-->
                                                    <!--                                                            === false ? `${item.exam_count + 1}次补考`-->
                                                    <!--                                                            : "点击报考"-->
                                                    <!--                                                            }}-->
                                                    <!--                                                        </el-button>-->
                                                    <!--                                                    </div>-->
                                                    <div style="margin-right: 10px"
                                                         v-if="ConditionsDisplay(item).allow_to_exam">
                                                        <el-button size="small" @click="toExam(item.id)">
                                                            {{
                                                            item.exam_record.length > 0 &&
                                                            item.exam_record[item.exam_record.length - 1].is_pass
                                                            === false ? `再次报考`
                                                            : "点击报考"
                                                            }}
                                                            <!--                                                            {{-->
                                                            <!--                                                            item.exam_record.length > 0 &&-->
                                                            <!--                                                            item.exam_record[item.exam_record.length - 1].is_pass-->
                                                            <!--                                                            === false ? `${item.exam_count + 1}次补考`-->
                                                            <!--                                                            : "点击报考"-->
                                                            <!--                                                            }}-->
                                                        </el-button>
                                                    </div>
                                                    <div>
                                                        <!--                                                        <el-button-->
                                                        <!--                                                                size="small"-->
                                                        <!--                                                                :disabled="-->
                                                        <!--                                                                  item.state_code < 3 ||-->
                                                        <!--                                                                  (item.state_code < 7 && item.exam_date)-->
                                                        <!--                                                                    ? false-->
                                                        <!--                                                                    : true-->
                                                        <!--                                                                "-->
                                                        <!--                                                                @click="toUpdate(item.id)"-->
                                                        <!--                                                        >编辑-->
                                                        <!--                                                        </el-button>-->
                                                        <el-button
                                                                icon="el-icon-edit"
                                                                size="small"
                                                                :disabled="!(ConditionsDisplay(item).allow_edit_1 || ConditionsDisplay(item).allow_edit_2)"
                                                                @click="toUpdate(item.id)"
                                                        >编辑
                                                        </el-button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </el-row>
                                    <el-row class="sign_content">
                                        <el-col v-if="item.org" :span="10">
                                            <p v-if="item.org.org_name">报名机构：{{ item.org.org_name }}({{
                                                item.org.org_code }})</p>
                                            <div v-if="!item.org.has_import">
                                                <div v-if="item.train_account && item.train_password">
                                                    <p>学习账号：{{ item.train_account }}</p>
                                                    <p>学习密码：{{ item.train_password }}</p>
                                                    <!--                                                    <p v-if="item.exp_date">账号期限：{{ item.exp_date | expDate }} 至 {{ item.exp_date | formatDate2 }}</p>-->
                                                    <p v-if="item.exp_date">账号期限：{{ item.active_date.substr(0,10)}} 至
                                                        {{item.exp_date.substr(0,10)}}</p>
                                                </div>
                                            </div>
                                            <!--                      <p v-if="item.train_account && item.train_password">-->
                                            <!--                        学习地址：<el-link type="primary" href="https://study.pta-athe.com/">-->
                                            <!--                        国际薪税师学习中心-->
                                            <!--                      </el-link>-->
                                            <!--                      </p>-->
                                            <!--                                            <p v-if="!item.exam_date">-->
                                            <!--                                                审核状态：<span-->
                                            <!--                                                    :style="-->
                                            <!--                                                      item.state_code == 8-->
                                            <!--                                                        ? 'color:green'-->
                                            <!--                                                        : 'color:orange'-->
                                            <!--                                                    "-->
                                            <!--                                            >{{dispalyMethod(item)}}</span>-->
                                            <!--                                            </p>-->
                                            <!--                                            <p v-if="isReject[item.state_code].includes('reject') && !item.exam_date">-->
                                            <!--                                                备注信息：<span-->
                                            <!--                                                    style="color: red"-->
                                            <!--                                                    v-if="isReject[item.state_code].includes('reject')"-->
                                            <!--                                                    v-text="item.audit_log[0].note"-->
                                            <!--                                            ></span>-->
                                            <!--                                            </p>-->
                                        </el-col>
                                        <el-col :span="10">

                                            <!--                                            <p>-->
                                            <!--                                                是否补考:-->
                                            <!--                                                <el-tag size="small">{{item.exam_count > 0 ? '是':'否'}}</el-tag>-->
                                            <!--                                            </p>-->
                                            <p v-if="item.exam_org">
                                                考试机构： {{ item.exam_org.org_name }}({{ item.exam_org.org_code }})
                                            </p>
                                            <p v-if="item.exam_date">
                                                考试形式： {{ item.exam_date.exam_city }}
                                            </p>
                                            <p v-if="item.exam_date">
                                                考试时间： {{ item.exam_date.time_detail }}
                                            </p>
                                            <!--                                            <p v-if="item.exam_date">-->
                                            <!--                                                审核状态：-->
                                            <!--                                                <span-->
                                            <!--                                                        :style="-->
                                            <!--                                                          item.state_code == 8-->
                                            <!--                                                            ? 'color:green'-->
                                            <!--                                                            : 'color:orange'-->
                                            <!--                                                        "-->
                                            <!--                                                                            >-->
                                            <!--                                                      {{ dispalyMethod(item) }}-->
                                            <!--                                                    </span-->
                                            <!--                                                    >-->
                                            <!--                                            </p>-->
                                            <p v-if="item.state_code == 8" style="color: green">
                                                准考证号： {{ item.exam_code }}
                                            </p>
                                            <!--                                            <p v-if="isReject[item.state_code].includes('reject') && item.exam_date">-->
                                            <!--                                                备注信息：-->
                                            <!--                                                <span-->
                                            <!--                                                        style="color: red"-->
                                            <!--                                                        v-if="isReject[item.state_code].includes('reject')"-->
                                            <!--                                                        v-text="item.audit_log[0].note"-->
                                            <!--                                                ></span>-->
                                            <!--                                            </p>-->
                                        </el-col>
                                    </el-row>
                                    <el-alert
                                            style="margin-top: 10px"
                                            :title="getAlertMessage(item).message.split('__')[1]"
                                            :type="getAlertMessage(item).message.split('__')[0]"
                                            show-icon
                                            :closable="false">
                                        <template v-if="getAlertMessage(item).note">
                                            <span style="color: red">{{getAlertMessage(item).note}}</span>
                                        </template>
                                    </el-alert>
                                </el-card>
                            </el-row>
                        </el-col>
                    </el-row>
                </div>
                <el-empty description="还没有报名记录" v-else>
                    <el-button size="mini" type="primary" @click="toRegister">点击报名</el-button>
                </el-empty>
            </div>
            <PersonVerify v-if="certified === false"></PersonVerify>
        </div>
        <footerComponent></footerComponent>
    </div>
</template>

<script>
    import {cert_list, work_duty_list,ind_typeList,com_typeList,hig_eduList} from "../../assets/staticList/index";
    import {formatDate} from "@/utils/formatDate";
    import PersonVerify from "@/components/PersonVerify/PersonVerify";
    import headerComponent from '@/components/headerComponent'
    import footerComponent from '@/components/footerComponent'
    import {
        generate_contract,
        generateContract,
        get_user_info,
        noticeList,
        profile,
        userExamReacord,
        userExtSign,
        viewContract
    } from "@/request/api";
    import {generate_contract_func, userExtSign_func} from "./genrate_contract_fun";

    export default {
        name: "index",
        filters: {
            hideMiddle(val) {
                if (val) {
                    return `${val.substring(0, 3)}****${val.substring(val.length - 3)}`
                } else {
                    return ''
                }
            },
            formatDate2(time) {
                let date = new Date(time);
                return formatDate(date, 'yyyy-MM-dd')
            },
            formatDate(time) {
                let date = new Date(time);
                return formatDate(date, 'yyyy年MM月dd日')
            },
            formatDateMath(time) {
                let date = new Date(time);
                return formatDate(date, 'yyyy年MM月')
            },
            expDate(time) {
                let date = new Date(time);
                date.setFullYear(date.getFullYear() - 1);
                return formatDate(date, 'yyyy-MM-dd')
            }
        },
        data() {
            return {
                activeName: 'register',
                workInfoIsShow: false,
                userInfoIsShow: false,
                notice: {},
                notiListDialogVisible: false,
                noticeList: [],
                personCopy: [],
                com_typeList: com_typeList,
                ind_typeList: ind_typeList,
                certDisplayOptions: cert_list,
                certified: null,
                person: {},
                profile: [],
                state_map: {
                    0: "机构一审驳回",
                    1: "机构一审待审",
                    2: "总部一审驳回",
                    3: "总部一审待审",
                    4: "机构二审驳回",
                    5: "机构二审待审",
                    6: "总部二审驳回",
                    7: "总部二审待审",
                    8: "全部审核通过",
                }, //审核状态字典
                state_to_code: {
                    "机构一审驳回": 0,
                    "机构一审待审": 1,
                    "总部一审驳回": 2,
                    "总部一审待审": 3,
                    "机构二审驳回": 4,
                    "机构二审待审": 5,
                    "总部二审驳回": 6,
                    "总部二审待审": 7,
                    "全部审核通过": 8,
                }, //审核状态字典
                isReject: {
                    0: "org_1_reject",
                    1: "org_1_wait",
                    2: "admin_1_reject",
                    3: "admin_1_wait",
                    4: "org_2_reject",
                    5: "org_2_wait",
                    6: "admin_2_reject",
                    7: "admin_2_wait",
                    8: "allpass",
                },
                currentProfile: {},
                cardOptions: {'1': "居民身份证", '2': "护照", '3': "港澳台胞身份证"}, //证件类型字典
                UserExamReacord: [],//报考记录
            }
        },
        methods: {
            //条件显示
            ConditionsDisplay(profile) {
                const state_code = profile.state_code
                const has_exam_code = profile.exam_code
                let edited = false
                if (profile.last_edit_date && profile.audit_log.length) {
                    edited = profile.last_edit_date > profile.audit_log[0].add_time
                }
                let allow_edit_1 = state_code < 3
                let allow_to_exam = !has_exam_code && state_code === 5 || (profile.exam_record.length && profile.exam_record[profile.exam_record.length - 1].is_pass === false)
                let allow_edit_2 = has_exam_code && [4, 5, 6].includes(state_code)
                let allow_sign = has_exam_code && (!profile.concratc_id || !profile.signed)
                let contract_reject = profile.audit_log.length && profile.audit_log[0].method.includes('contract_reject') && !profile.signed
                return {
                    allow_edit_1,
                    allow_to_exam,
                    allow_edit_2,
                    allow_sign,
                    contract_reject
                }
            },
            getAlertMessage(profile) {
                const status_code = profile.state_code
                const has_exam_code = profile.exam_code ? true : false
                let edited = false
                if (profile.last_edit_date && profile.audit_log.length) {
                    edited = !profile.audit_log[0].method.includes('contract_reject') && profile.last_edit_date > profile.audit_log[0].add_time
                }
                let signed = has_exam_code && (profile.contract_id && profile.signed);
                let note = profile.audit_log.length ? profile.audit_log[0].note : ''
                let contract_reject_code = profile.audit_log.length && (profile.audit_log[0].method == 'org_contract_reject' || profile.audit_log[0].method == 'admin_contract_reject') ? profile.audit_log[0].method : null;
                // console.log(status_code, status_code === 5 ? has_exam_code : edited, signed, contract_reject_code)
                let message = this.alert_msg(status_code, status_code === 5 ? has_exam_code : edited, signed, contract_reject_code);
                return {
                    message,
                    note
                }
            },
            //行为提示
            alert_msg(status_code, edited, signed, contract_reject_code) {
                //status_code 状态码 edited，signed 必须是布尔值
                const msg_list = [
                    ['error__培训报名资料被机构驳回，请点击【编辑】按钮修改后提交。', 'info__等待机构审核。'],
                    'info__等待机构审核。',
                    [`error__培训报名资料被总部驳回，请点击【编辑】按钮修改后提交。`, 'info__等待机构审核。'],
                    'success__培训报名资料机构审核通过，等待总部审核。',
                    ['error__考试报名资料被机构驳回，请点击【编辑】按钮修改后提交。', 'warning__考试报名资料已提交，但还未签署确认书，请点击【继续签署报考确认书】按钮，完成签署操作。', 'info__考试报名资料已提交，等待机构审核。'],
                    ['success__培训报名资料总部审核通过。', 'warning__您提交了考试报名资料但还未签署确认书，请点击【继续签署报考确认书】按钮，完成签署操作。', 'info__考试报名资料已提交，等待机构审核。'],
                    ['error__考试报名资料被总部驳回，请点击【编辑】按钮修改后提交。', 'warning__考试报名资料已提交，但还未签署确认书，请点击【继续签署报考确认书】按钮，完成签署操作。', 'info__考试报名资料已提交，等待机构审核。'],
                    'success__考试报名资料机构审核通过，等待总部审核。',
                    'success__考试报名资料审核已全部通过。'
                ];
                // const msg_list = [
                //     ['error__资料被机构驳回，请重新编辑', 'info__等待机构审核中'],
                //     'info__等待机构审核中',
                //     [`error__资料被总部驳回，请重新编辑`, 'info__等待机构审核中'],
                //     'success__资料机构审核通过,等待总部审核',
                //     ['error__资料被机构驳回，请重新编辑', 'warning__资料已编辑，但报考确认书未签署', 'info__资料机构审核中'],
                //     ['success__资料总部审核通过,可参与报考', 'warning__您提交了报考表单但未签署', 'info__资料机构审核中'],
                //     ['error__资料被总部驳回，请重新编辑', 'warning__资料已编辑，但报考确认书未签署', 'info__资料机构审核中'],
                //     'success__资料机构审核通过,等待总部审核',
                //     'success__资料审核已全部通过'
                // ]
                const contract_list = {
                    'org_contract_reject': 'warning__报考确认书已被机构驳回，请点击【继续签署报考确认书】按钮，重新签署。',
                    'admin_contract_reject': 'warning__报考确认书已被总部驳回，请点击【继续签署报考确认书】按钮，重新签署。'
                };
                if (contract_reject_code) {
                    if (signed) {
                        let msg = contract_reject_code.includes('org') ? 'warning__报考确认书已签署，等待机构审核。' : 'warning__报考确认书已签署，等待总部审核。';
                        return msg
                    }
                    let msg = contract_list[contract_reject_code];
                    return msg
                }
                let msg = msg_list[status_code]
                return typeof (msg) === 'string' ? msg : msg[edited + signed]
            },
            showNoti(title) {
                console.log('公告标题', title);
                this.notiListDialogVisible = true;
                for (let item of this.noticeList) {
                    if (item.title == title) {
                        this.notice = item
                    }
                }
            },
            //审核方法显值
            dispalyMethod(item) {
                let has_audit_log = item.audit_log.length > 0;
                if (!has_audit_log) {
                    return '机构一审待审'
                }
                let last_edit_date = item.last_edit_date || '1970-12-12';
                let method = item.audit_log[0].method
                let last_audit_date = item.audit_log[0].add_time
                let state_code = item.state_code
                //修饰状态码部分
                ////总部二审驳回变成机构二审待审
                if (last_edit_date > last_audit_date && method === 'admin_reject_2') {
                    state_code = this.state_to_code['机构二审待审']
                }//总部一审驳回变成机构一审待审
                else if (last_edit_date > last_audit_date && method === 'admin_reject_1') {
                    state_code = this.state_to_code['机构一审待审']
                } //驳回后编辑状态码+1
                else if (method.includes('reject_') && last_edit_date > last_audit_date) {
                    state_code += 1
                }
                //修饰名称部分
                let display_method = this.state_map[state_code] //状态码获取状态名

                if (state_code === this.state_to_code['机构二审待审'] && !item.exam_date) {
                    display_method = '培训报名已完成,待报考'
                }
                return display_method
            },
            async to_contract(profile) {
                const contract_id = profile.contract_id
                const signed = profile.signed
                const last_method = profile.audit_log.length ? profile.audit_log[0].method : 'null'
                let must_generate_contract = !contract_id || (contract_id && last_method.includes('reject') && !signed)
                //must_generate_contract 为true填充合同
                if (must_generate_contract) {
                    await generate_contract_func(profile)
                }
                userExtSign_func(profile)

            },
            //查看合同
            lookTransation(contract_id) {
                viewContract({contract_id: contract_id}).then((res) => {
                    window.open(res.view_url);
                });
            },
            //获取公告
            NoticeList() {
                noticeList().then(res => {
                    console.log('公告列表', res);
                    this.noticeList = res
                })
            },
            //学员获取报考记录
            getUserExamReacord() {
                userExamReacord().then(res => {
                    this.getUserExamReacord = res;
                })
            },
            //去编辑
            toUpdate(pid) {
                this.$router.push({name: 'userUpdate', params: {'update_id': pid}})
            },
            //去报考
            toExam(pid) {
                this.$router.push({name: 'userExam', params: {'exam_id': pid}})
            },
            ReverseRankingDate(data, p) {
                for (let i = 0; i < data.length - 1; i++) {
                    for (let j = 0; j < data.length - 1 - i; j++) {
                        // console.log(Date.parse(data[j][p]));
                        if (Date.parse(data[j][p]) > Date.parse(data[j + 1][p])) {
                            var temp = data[j];
                            data[j] = data[j + 1];
                            data[j + 1] = temp;
                        }
                    }
                }
                return data;
            },
            //获取档案信息
            getProfile() {
                profile().then(res => {
                    console.log('档案信息', res);
                    this.profile = JSON.parse(JSON.stringify(res));
                    console.log('this.profile', this.profile)
                    let newProfile = this.ReverseRankingDate(res, "update_time");
                    console.log('newProfile', newProfile)
                    if (newProfile.length > 0) {
                        this.personCopy = JSON.parse(JSON.stringify(newProfile[newProfile.length - 1]));
                        for (let item of newProfile) {
                            for (let key in item) {
                                if (item[key] !== null && item[key] !== "") {
                                    this.personCopy[key] = item[key];
                                }
                            }
                        }
                        this.person = this.personCopy
                        // console.log('this.person',this.person)
                    }
                })
            },
            toRegister() {
                this.$router.push({path: '/user/register'})
            },
            getUserInfo() {
                get_user_info().then(res => {
                    console.log(res)
                    this.certified = res.certified;
                }).catch(err => {
                    this.$message({type: 'error', message: err.msg})
                })
            }
        },
        created() {
            this.getUserExamReacord();
            this.getUserInfo();
            this.getProfile();
            this.NoticeList();
        },
        components: {
            headerComponent,
            footerComponent,
            PersonVerify
        }
    }
</script>

<style>
    .tab .el-tabs__nav {
        width: 100%;
    }

    .tab .el-tabs__item {
        text-align: center;
        width: 50%;
    }

    .el-empty {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
    }
</style>

<style scoped>
    .personContent {
        width: 100%;
        background-image: url("../../assets/background/bg.jpg");
        min-height: calc(100vh - 120px);
    }

    .center {
        width: 1200px;
        margin: 0 auto;
        min-height: calc(100vh - 120px);
    }

    .sign_content {
        font-size: 14px;
        line-height: 1.6;
        margin-top: 10px;
        margin-left: 20px;
    }

    .userinfo {
        margin-top: 10px;
    }

    .userinfo p {
        font-size: 14px;
        line-height: 1.6;
    }

    .sign_step p {
        font-size: 14px;
        line-height: 1.6;
    }

    .notilist :hover {
        cursor: pointer;
        color: #409EFF;
    }

    .notilist {
        line-height: 25px;
        font-size: 14px;
    }

    .notilist_span {
        width: 400px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .h6 {
        font-size: 14px;
        font-weight: normal;
        margin-bottom: 10px;
    }

    h5 {
        font-size: 14px;
        font-weight: normal;
    }
</style>
